package com.xiaoxu.controller;

import com.xiaoxu.damain.UserData;
import com.xiaoxu.damain.Userinfo;
import com.xiaoxu.service.Loginservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;

import java.text.SimpleDateFormat;
import java.util.List;

@RestController
@RequestMapping("/userlogin")
@CrossOrigin
public class LoginController {
    @Autowired
    private Loginservice loginservice;

    @PostMapping
    public Userinfo SelectAll(@RequestBody UserData logininfo){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        UserData logininfo2 = new UserData();
        BeanUtils.copyProperties(logininfo,logininfo2);
        System.out.println(logininfo2.toString());
        System.out.println(loginservice.SelectAll(logininfo2));
        Userinfo info = new Userinfo();
        BeanUtils.copyProperties(loginservice.SelectAll(logininfo2),info);
        String birthday =df.format(loginservice.SelectAll(logininfo2).getUser_birthday());
        String createdate =df.format(loginservice.SelectAll(logininfo2).getUser_createdate());
        info.setUser_birthday(birthday);
        info.setUser_createdate(createdate);
        System.out.println(info);
        return info;
    }

}
